package com.blog.user.controller;

import com.blog.response.Result;
import com.blog.user.pojo.AuthRole;
import com.blog.user.service.AuthRoleService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate;

import java.util.List;

@RestController
@RequestMapping("/authRole")
public class AuthRoleController {

    @Autowired
    private AuthRoleService authRoleService;
    @Autowired
    private RestTemplate restTemplate;

    @GetMapping("/findAll")
    public Result findAll(int page, int size, String query) {
        List<AuthRole> list = authRoleService.findAll(page, size, query);
        return Result.ok(list);
    }

    @GetMapping("/findById")
    public Result findById(String id) {
        AuthRole authRole = authRoleService.findById(id);
        return Result.ok(authRole);
    }

    @PostMapping("/saveOrUpdate")
    public Result saveOrUpdate(AuthRole authRole) {
        boolean isAdd = StringUtils.isBlank(authRole.getId());
        if (isAdd){
            authRoleService.insert(authRole);
        } else {
            authRoleService.update(authRole);
        }
        return Result.ok("保存成功！");
    }

    @DeleteMapping("/delete")
    public Result deleteByIds(String[] ids) {
        for(String id: ids) {
            authRoleService.deleteById(id);
        }
        return Result.ok("删除成功！");
    }

}